package com.zhengqing.softdemo.entity.table

import com.mybatisflex.core.query.QueryColumn
import com.mybatisflex.core.table.TableDef

/**
 * 表定义层。
 *
 * @author zql
 * @since 2024-04-25
 */
class SoftTableDef : TableDef {
    val ID = QueryColumn(this, "id")
    val STAR = QueryColumn(this, "star")
    val UUID = QueryColumn(this, "uuid")
    val GIT_URL = QueryColumn(this, "git_url")
    val SOFT_ID = QueryColumn(this, "soft_id")
    val STATUS = QueryColumn(this, "status")
    val SOFT_NAME = QueryColumn(this, "soft_name")
    val CREATED_AT = QueryColumn(this, "created_at")
    val IS_DELETED = QueryColumn(this, "is_deleted")
    val LANGUAGES = QueryColumn(this, "languages")
    val UPDATED_AT = QueryColumn(this, "updated_at")
    val OFFICIAL_URL = QueryColumn(this, "official_url")
    val SOFT_VERSION = QueryColumn(this, "soft_version")
    val MAIN_LANGUAGE = QueryColumn(this, "main_language")

    /**
     * 所有字段。
     */
    val ALL_COLUMNS = QueryColumn(this, "*")

    /**
     * 默认字段，不包含逻辑删除或者 large 等字段。
     */
    val DEFAULT_COLUMNS = arrayOf(ID, SOFT_NAME, SOFT_VERSION, GIT_URL, OFFICIAL_URL, MAIN_LANGUAGE, LANGUAGES, STAR, UUID, SOFT_ID, CREATED_AT, UPDATED_AT, STATUS, IS_DELETED)

    constructor() : super("", "tb_soft")
    private constructor(schema: String, name: String, alisa: String) : super(schema, name, alisa)

    override fun `as`(alias: String): SoftTableDef {
        val key = "$nameWithSchema.$alias"
        return getCache(key) { k: String? -> SoftTableDef("", "tb_soft", alias) }
    }

    companion object {
        private const val serialVersionUID = 1L

        /**
         *
         */
        val SOFT = SoftTableDef()
    }
}